//
//  InputTitleCell.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/12/9.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift
import RxSwift

class InputTitleCell: UITableViewCell {

    @IBOutlet weak var tf: UITextField!
    
    let bag = DisposeBag()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
//        contentView.backgroundColor = .random()
    }
    
    override func bindTo(_ info: Any?) {
        self.info = info
//        contentView.backgroundColor = .random()
        
        /// 一次性配置
        if let config = info as? TableCellConfigProtocol {
            if config.isConfigDone == false { /// 判断是否加载过
                config.isConfigDone = true
                if let form = info as? FormModelProtocol { /// 表单判断约束
                    if form.rules.count > 0 {
                        LimitInputHelper.tf(tf, rules: form.rules, bag: bag) {
                            form.keyValue = $0
                        }
                    }
                }
            }
        }
        
        /// 多次配置
        if let _ = info as? TableCellConfigProtocol {
            if let form = info as? FormModelProtocol { /// 表单判断约束
                self.tf.text = form.keyValue
            }
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
